<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'普通用户列表'),
	array('op'=>'vip','title'=>'会员列表'),
	array('op'=>'black','title'=>'黑名单'),	
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=0;
	$params['isvip']=0;
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_kecheng_user',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'status','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'昵称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='vip'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=0;
	$params['isvip']=1;
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','mid','nickname','avatar','red_get','red_pay','money_get','money_pay','cash','isvip','viptime','description','status','createtime');
	$list=pdo_getslice('jy_kecheng_user',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'money_get','title'=>'获得打赏总金额','type'=>'string'),
			array('name'=>'cash','title'=>'可提现金额','type'=>'string'),
			array('name'=>'viptime','title'=>'会员到期时间','type'=>'time'),
			array('name'=>'status','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'昵称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='black'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=1;
	$params['isvip']=1;
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','mid','nickname','avatar','red_get','red_pay','money_get','money_pay','cash','isvip','viptime','description','status','createtime');
	$list=pdo_getslice('jy_kecheng_user',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'money_get','title'=>'获得打赏总金额','type'=>'string'),
			array('name'=>'cash','title'=>'可提现金额','type'=>'string'),
			array('name'=>'status','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'昵称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kecheng_user',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array('get_type'=>0);
	}
	$item['viptime']=date('Y-m-d H:i:s',$item['viptime']);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回用户列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
						array(
							'title'=>'基本信息',
							'list'=>array(
								array('name'=>'viptime','title'=>'VIP到期时间','type'=>'time'),
								array('name'=>'isvip','title'=>'已开通VIP','type'=>'radio','options'=>'jsjiqi'),
							)
						),
			
			)
	);
	$return['jsjiqi']=array('未开通','已开通');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'isvip'=>intval($postdata['isvip']),
		'viptime'=>strtotime($postdata['viptime']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_kecheng_user',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_kecheng_user',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_kecheng_user',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的用户！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_kecheng_user',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}